package main

//@url: https://leetcode-cn.com/problems/longest-arithmetic-subsequence-of-given-difference/

func longestSubsequence(arr []int, difference int) int {
	mmap := make(map[int]int) // mmap[i] = j 表示以i结尾的等差序列长度为j
	var res = 0
	for i := 0; i < len(arr); i++ {
		mmap[arr[i]] = mmap[arr[i]-difference] + 1
		if mmap[arr[i]] > res {
			res = mmap[arr[i]]
		}
	}
	return res
}
